﻿--
--
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'dsZeusPackageInventoryInfo' AND type = 'P')
BEGIN
  DROP PROCEDURE dsZeusPackageInventoryInfo
END
GO

-- HU - Rakomány info
-- EN - Package information
--
CREATE PROCEDURE dsZeusPackageInventoryInfo
(@AccessToken INTEGER, @Code NVARCHAR(20))
 AS
BEGIN
  DECLARE
    @Err INTEGER,
    @Rows INTEGER,
    @UserID INTEGER,
    @Lang NVARCHAR(10)

  EXEC @Err = spAccessTokenCheck @AccessToken, @UserID OUTPUT, @Lang OUTPUT

  IF (@Err != 0)
    GOTO __ERROR__

  --
  --
  IF NOT EXISTS (SELECT ID FROM ZeusPackage WHERE Code = @Code) BEGIN

    IF (@Lang = 'HU')
      RAISERROR (N'Nincs ilyen rakomány ! %s', 16, 1, @Code)

    IF (@Lang = 'EN')
      RAISERROR (N'Package not found ! %s', 16, 1, @Code)
      
    IF (@Lang = 'DE')
      RAISERROR (N'Keine solche Fracht ! %s', 16, 1, @Code)

    GOTO __ERROR__
  END

  -- HU - Visszaadja ennek a Rakománynak az adatait
  -- EN - Get the package details
  --    
  SELECT p.Code, p.ArticleCode, p.ArticleName, 
    
         CAST(p.Expired as DATE) Expired, 
         
         i.Location1, i.Quantity1, i.Location2, i.Quantity2, p.UnitCode, N'' Notes

    FROM ZeusPackage p
    LEFT JOIN ZeusInventory i ON p.Code = i.PackageCode
   WHERE p.Code = @Code

-- Well done.
--
  RETURN(0)

-- We have a problem !
--
__ERROR__:
  RETURN(1)
END
GO
